package com.jrwd.recycletest;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.jrwd.recycletest.util.ScreenUtils;


/**
 * Created by Koma on 2017/6/13.
 * Description：提示对话框
 * version 1.0 Content：
 */

public class HintDialog extends Dialog {

    /**
     * 确定按钮
     */
    private TextView tv_sure;
    private TextView tv_cancle;

    public HintDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    public HintDialog(Context context, String title, String message) {
        super(context);
        init(context, title, message, "确定");
    }

    public HintDialog(Context context, int message, String sure) {
        super(context);
        init(context, "提示", context.getString(message), sure);
    }

    public HintDialog(Context context, String title, int message, String sure) {
        super(context);
        init(context, title, context.getString(message), sure);
    }

    public HintDialog(Context context, String title, String message, String sure) {
        super(context);
        init(context, title, message, sure);
    }



    private void init(Context context, String title, String message, String sure) {
        //无标题
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.dialog_hint, null);

        TextView tv_title = (TextView) view.findViewById(R.id.tv_title);
        TextView tv_message = (TextView) view.findViewById(R.id.tv_message);
        tv_cancle = (TextView) view.findViewById(R.id.tv_cancle);
        tv_sure = (TextView) view.findViewById(R.id.tv_sure);

        tv_title.setText(title);
        tv_message.setText(message);
        tv_sure.setText(sure);
        tv_cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cancel();
            }
        });

        setContentView(view);
        setCancelable(true);
        getWindow().getDecorView().setBackgroundColor(Color.TRANSPARENT);
        WindowManager.LayoutParams params = this.getWindow().getAttributes();//获取dialog信息
        params.width = ScreenUtils.getScreenWidth(context)-20;
        this.getWindow().setAttributes(params);//设置大小
    }

    /**
     * 按钮点击事件
     */
    public void setSureOnclick(View.OnClickListener clickListener){
        tv_sure.setOnClickListener(clickListener);
    }

    public void setCancelOnclick(View.OnClickListener clickListener){
        tv_cancle.setOnClickListener(clickListener);
    }


}
